/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.event.khachhang;

import control.khachhang.KHMainPanel_ctrl;
import gui.event.ulti.Util;
import gui.khachhang.KHChiTiet_Dialog;
import gui.khachhang.KHPhucHoi_Dialog;
import gui.khachhang.KHSaoLuu_Dialog;
import gui.khachhang.KHSuaThongTin_Dialog;
import gui.khachhang.KHThem_Full;
import java.awt.print.PrinterException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import model.entity.KhachHang;

/**
 *
 * @author nv_ca@live.com
 */
public class KHMainPanel_evt {

    public static final void btnThemActionPerformed(JTable table) {
        KHThem_Full khThemFull = new KHThem_Full(table, null, true);
        khThemFull.setLocationRelativeTo(null);
        khThemFull.setVisible(true);
    }
/**
 * 
 * @param table là lấy thông tin từ cái bảng 
 */
    public static final void btnSuaActionPerformed(JTable table) {
        KhachHang kh = KHMainPanel_ctrl.selectRow(table);
        System.out.println("----" + kh.getKhMa());
        KHSuaThongTin_Dialog khSuaDlg = new KHSuaThongTin_Dialog(table, null, true);
        khSuaDlg.getTxtMaKH().setText(""+kh.getKhMa());
        khSuaDlg.getTxtHo().setText(""+kh.getKhHo());
        khSuaDlg.getTxtTen().setText(""+kh.getKhTen());
        khSuaDlg.getTxtSoDT().setText(""+kh.getKhSdt());
        khSuaDlg.getjDateChooser1().setDate(kh.getKhNgaySinh());
        khSuaDlg.getTxtDiaChi().setText(""+kh.getKhDiaChi());
        khSuaDlg.getTaGhiChu().setText(""+kh.getKhGhiChu());
        
        khSuaDlg.setLocationRelativeTo(null);
        khSuaDlg.setVisible(true);
    }

    public static final void btnInActionPerformed(JTable table) {
        try {
            table.print();
        } catch (PrinterException ex) {
            Logger.getLogger(KHMainPanel_evt.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
/**
 * 
 * @param table 
 */
    public static final void btnChiTietActionPerformed(JTable table) {
        KhachHang kh = KHMainPanel_ctrl.selectRow(table);
        
        KHChiTiet_Dialog khChiTietDlg = new KHChiTiet_Dialog(null, true);
        
        khChiTietDlg.getTxtMaKH().setText(""+kh.getKhMa());
        khChiTietDlg.getTxtHoVaTen().setText(""+kh.getKhHo()+ "" +kh.getKhTen());
        khChiTietDlg.getTxtGioiTinh().setText(""+kh.getKhGioiTinh());
        khChiTietDlg.getTxtDiaChi().setText(""+kh.getKhDiaChi());
        khChiTietDlg.getTxtSDT().setText(""+kh.getKhSdt());
        // goi ham tu model lay danh sach vat nuoi theo ma
        //lay khChiTietDlg lay jtable set cac du lieu len
        KHMainPanel_ctrl.loadVatNuoiTheoMaKH(khChiTietDlg.getTblVatNuoi(), kh.getKhMa());
        
        khChiTietDlg.setLocationRelativeTo(null);
        khChiTietDlg.setVisible(true);
    }

    public static final void btnCloseActionPerformed(JPanel pnl, JTabbedPane jTabbedPane) {
        Util.closeATab(pnl.getName(), jTabbedPane);
    }

    public static final void btnLietKeActionPerformed() {
//        JOptionPane.showMessageDialog(null, "Chỗ này dính tới query, làm sau.");
    }

    public static final void btlKhachHangFocusGained(List<JButton> listButtons, JTable table) {
//        if (table.getSelectedRowCount() == 1) 
            Util.enableListButtons(listButtons);
    }

    public static final void btlKhachHangFocusLost(List<JButton> listButtons) {
            Util.disableListButtons(listButtons);
    }

    public static final void enableListComponents(List<JComponent> components) {
        Util.enableListComponents(components);
    }

    public static final void disableListComponents(List<JComponent> components) {
        Util.disableListComponents(components);
    }

    public static final void btnThucHienSaoLuuActionPerformed() {
        KHSaoLuu_Dialog khSaoLuuDlg = new KHSaoLuu_Dialog(null, true);
        khSaoLuuDlg.setLocationRelativeTo(null);
        khSaoLuuDlg.setVisible(true);
    }

    public static final void btnThucHienPhucHoiActionPerformed() {
        KHPhucHoi_Dialog khPhucHoiDlg = new KHPhucHoi_Dialog(null, true);
        khPhucHoiDlg.setLocationRelativeTo(null);
        khPhucHoiDlg.setVisible(true);
    }
}
